using System;
using UnityEngine;
using Voodoo.GameOps;
using Voodoo.Pattern;

public class UpgradeFX : MonoBehaviour
{
	private int lastUpgradeLevel = -1;

	public Item upgradeItem;

	public GameObject FX;

	private void Start()
	{
		RefreshFX();
		GameManager instance = SingletonMB<GameManager>.Instance;
		instance.OnGameStart = (Action)Delegate.Combine(instance.OnGameStart, new Action(DeactivateFX));
		InventoryManager instance2 = InventoryManager.Instance;
		instance2.OnItemPurchased = (Action)Delegate.Combine(instance2.OnItemPurchased, new Action(RefreshFX));
	}

	private void OnDestroy()
	{
		if (SingletonMB<GameManager>.Instance != null)
		{
			GameManager instance = SingletonMB<GameManager>.Instance;
			instance.OnGameStart = (Action)Delegate.Remove(instance.OnGameStart, new Action(DeactivateFX));
		}
		if (InventoryManager.Instance != null)
		{
			InventoryManager instance2 = InventoryManager.Instance;
			instance2.OnItemPurchased = (Action)Delegate.Remove(instance2.OnItemPurchased, new Action(RefreshFX));
		}
	}

	private void DeactivateFX()
	{
		FX.SetActive(value: false);
	}

	private void RefreshFX()
	{
		if (lastUpgradeLevel >= 0 && lastUpgradeLevel != InventoryManager.Instance.GetInventoryCount(upgradeItem))
		{
			SingletonMB<GameManager>.Instance.GameplayHaptic.PlayHaptic(HapticType.Small);
			FX.SetActive(value: false);
			FX.SetActive(value: true);
		}
		else
		{
			FX.SetActive(value: false);
		}
		lastUpgradeLevel = InventoryManager.Instance.GetInventoryCount(upgradeItem);
	}
}
